package com.example.imitationoftodaysheadlines;

import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private  static List<NewsBean> newsBeanList=new ArrayList<>();
    @SuppressLint("WrongViewCast")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        // 数据
        for (int i = 0; i <3;i++) {
            NewsBean newsBean1 = new NewsBean("各地餐企齐行动，杜绝餐饮浪费", "央视新闻客户端", "9984", "6小时前", 0);
            newsBeanList.add(newsBean1);
            NewsBean newsBean2 = new NewsBean("花菜有人焯水，有人直接炒，都错了，看饭店大厨如果做的", "美味食记", "18", "刚刚", R.drawable.food);
            newsBeanList.add(newsBean2);
        }
        // 数据适配器
        RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter(newsBeanList);
        // RecyclerView setAdapter
       ((RecyclerView) findViewById(R.id.recyclerView)).setAdapter(recyclerViewAdapter);
       RecyclerView recyclerView = findViewById(R.id.recyclerView);

       recyclerView.setLayoutManager(new LinearLayoutManager( MainActivity.this , LinearLayoutManager.VERTICAL , false));
       recyclerView.setAdapter(recyclerViewAdapter);
       //间隔线
       //间隔线
       DividerItemDecoration dividerItemDecoration=
               new DividerItemDecoration(MainActivity.this,
                       DividerItemDecoration.VERTICAL);
       Drawable drawable= ContextCompat.getDrawable(
               MainActivity.this,R.drawable.line);
       dividerItemDecoration.setDrawable(drawable);
       recyclerView.addItemDecoration(dividerItemDecoration);


    }
}